let dbUtils = require('./dbUtils');


async function handleAsync(cb, params) {
  try {
    let res = await cb(params);
    return [null, res];
  } catch (e) {
    return [e, null]
  }
}

async function main() {
  // 优雅的处理async await 成功或者失败
  // let [err, res] = await handleAsync(dbUtils, ('select DISTINCT type from inter'));
  // if (err) {
  //   console.log(err);
  // } else {
  //   res.forEach(item => {
  //     dbUtils(`insert into type (typename) values ("${item.type}") `);
  //   })
  // }

  let [err, res] = await handleAsync(dbUtils, 'select * from inter');
  if (err) {
    console.log(err);
  } else {
    res.forEach(async item => {
      let {type, title} = item;
      let types = await dbUtils(`select * from type where typename='${type}'`);
      console.log(types[0]['tid']);
      dbUtils(`insert into question (content,tid) values ("${title}",${types[0]['tid']}) `);
    })
  }
}

main();

// 1. 编写好的md文件  转换 md  html
// 2. v-html
